Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Partial Class TheatreStaff_Schedule
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(sender As Object, e As EventArgs)
		srcSchedule.SelectParameters("username").DefaultValue = Page.User.Identity.Name
		srcgrdSchedule.SelectParameters("username").DefaultValue = Page.User.Identity.Name

		Dim connectionString As String
		connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

		Dim con As New SqlConnection(connectionString)
		Dim cmd As New SqlCommand("SELECT TheatreId from TheatreStaff WHERE TheatreStaffUsername=@username", con)

		cmd.Parameters.AddWithValue("@username", Page.User.Identity.Name)

		Using con
			con.Open()
			Dim TheatreID As Object = cmd.ExecuteScalar()
			If TheatreID IsNot Nothing Then
				lblId.Text = TheatreID.ToString()
			End If
		End Using
		Dim con1 As New SqlConnection(connectionString)
		Dim cmd1 As New SqlCommand("SELECT Theatrename from Theatre WHERE Theatreid=@theatreid", con1)

		cmd1.Parameters.AddWithValue("@theatreid", lblId.Text)


		Using con1
			con1.Open()
			Dim Theatrename As Object = cmd1.ExecuteScalar()

			If Theatrename IsNot Nothing Then

				Label4.Text = Theatrename.ToString()
			End If
		End Using

    End Sub
    Protected Sub btnOk_Click(ByVal sender As Object, ByVal e As EventArgs)
        srcSchedule.InsertParameters("TheatreId").DefaultValue = lblId.Text
        grdSchedule.DataBind()
    End Sub
    Protected Sub dtlSchedule_ItemInserted(ByVal sender As Object, ByVal e As DetailsViewInsertedEventArgs)
        grdSchedule.DataBind()
    End Sub
    Protected Sub dtlSchedule_ItemUpdated(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs)
        grdSchedule.DataBind()
    End Sub
    Private Sub Page_Load()
        If Not Page.IsPostBack Then
            grdSchedule.SelectedIndex = 0
        End If
    End Sub
End Class
